package com.andy.controller;

import com.andy.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CodeController {

    @Autowired
    private CodeService codeService;

    /**
     * 创建并发送验证码给邮箱
     * @param email
     * @return
     */
    @RequestMapping("/code/create/{email}")
    public boolean create(@PathVariable String email){
        return codeService.create(email);
    }

    /**
     * 验证验证码
     * @param email
     * @param code
     * @return  校验验证码是否正确，0正确1错误2超时
     */
    @RequestMapping("/code/validate/{email}/{code}")
    public int validate(@PathVariable String email,@PathVariable String code){
        return codeService.validate(email,code);
    }
}
